A Ruby script is more than a sequence of commands; it is a structured anatomy that transitions from a static file to a live process. This lifecycle is governed by the Interpreter parsing exactly three expression types: Literals (fixed values), Variable references, and Method invocations.
1. The Syntactic Foundation
Ruby reserves specific keywords—captured in Table 22.3 (e.g., alias, class, yield)—that serve as the language's skeletal structure. These cannot be used as identifiers, ensuring the parser can distinguish logic from data.
2. The Execution Gate
A critical pattern for modular design is if __FILE__ == $0. This identifies if the file is the entry point (main script) or being loaded as a library. By leveraging __FILE__ and __LINE__, a program maintains self-awareness within the filesystem.
3. Embedded Data
The __END__ token acts as a physical trailer. The interpreter ignores everything following it, but provides the data via the DATA IO object, allowing for self-contained configuration or templates.